<script setup lang="ts">
  import type { BannerItem } from '@/types/home'
  import { ref } from 'vue'

  const activeIndex = ref(0)
  // swiper 滑动的回调
  const onChange: UniHelper.SwiperOnChange = e => {
    // 获取下标
    activeIndex.value = e.detail.current
  }
  defineProps<{
    list: BannerItem[]
  }>()
</script>

<template>
  <view class="carousel">
    <swiper :circular="true" :autoplay="true" :interval="3000" @change="onChange">
      <swiper-item v-for="item in list" :key="item.id">
        <navigator url="index" hover-class="none" class="navigator">
          <image mode="aspectFill" class="image" :src="item.imgUrl"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 指示点 -->
    <view class="indicator">
      <text
        v-for="(item, index) in list"
        :key="item.id"
        class="dot"
        :class="{ active: index === activeIndex }"
      ></text>
    </view>
  </view>
</template>

<style lang="scss">
  @use './styles/XtxSwiper.scss';
</style>
